package appli;

import gmusic.bo.ArtistBean;
import gmusic.dao.GMusicDAO;
import gmusic.dao.impl.GMusicDAOImpl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

public class ConsultGMArtist extends ApplicationLC {

	public static final String VERSION = "1.0.0.0";

	public static final String VERSION_DATE = "09/02/2009";

	private static final Logger log = Logger.getLogger(ConsultMAArtist.class);

	private String nomArtiste;

	public ConsultGMArtist(String[] args) throws SQLException {

		super();

		if (!controlArguments(args)) {
			afficherUsage();
			arretExecution(1);
		}

		log.info("Recherche de '" + nomArtiste + "'");
		GMusicDAO gmd = GMusicDAOImpl.getInstance();
		List<ArtistBean> artistes = gmd.rechercherArtiste(nomArtiste);

		log.info(artistes.size() + " artiste(s) trouve(s) : ");
		for (int i = 0; i < artistes.size(); i++) {
			log.info(artistes.get(i));
		}

		arretExecution(0);
	}

	@Override
	protected void afficherUsage() {
		log.info("Usage : java appli.ConsultGMArtist <nom artiste>");
	}

	@Override
	protected boolean controlArguments(String[] args) {

		if (args.length != 1) {
			log.error("Nombre d'argments invalide");
			return false;
		}
		nomArtiste = args[0];
		log.debug("Argument : " + nomArtiste);

		return true;
	}

	/**
	 * @param args
	 * @throws SQLException
	 */
	public static void main(String[] args) throws SQLException {

		new ConsultGMArtist(args);
	}

}
